<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>    
<%

String userId = request.getParameter("userId");
String userPw = request.getParameter("userPw");


String DB_URL = "jdbc:mysql://localhost:3306/bbs?useUnicode=true&characterEncoding=utf8";
String DB_USER = "root";
String DB_PASSWORD = "root";

Connection conn = null;
Statement stmt = null;
ResultSet result = null;

String query = "SELECT id,password FROM member WHERE 1=1 and id='"+userId+"' and password='"+userPw+"'";

//out.println(query);


try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWORD);
stmt = conn.createStatement();
result = stmt.executeQuery(query);

	if(result.next()){
	    session.setAttribute("id",result.getString(1));
	    session.setAttribute("password",result.getString(2));
	    
	    result.close();
	    stmt.close();
	    conn.close();
	    //out.println(session.getAttribute("id"));
	    response.sendRedirect("list.jsp");
	}
	
	out.println("<SCRIPT type='text/javascript'>");
	out.println("alert('아이디 또는 비밀번호가 잘못 되었습니다.');");
	out.println("history.back();");
	out.println("</SCRIPT>");
	result.close();
	stmt.close();
	conn.close();
	
}catch(Exception e){
	e.printStackTrace();
}



%>